define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'risk/reorder/index' + location.search,
                    add_url: 'risk/reorder/add',
                    // edit_url: 'risk/reorder/edit',
                    // del_url: 'risk/reorder/del',
                    multi_url: 'risk/reorder/multi',
                    import_url: 'risk/reorder/import',
                    table: 'risk',
                }
            });

            var table = $("#table");
            Fast.config.openArea = ['80%','70%'];
            //在普通搜索渲染后
            table.on('post-common-search.bs.table', function (event, table) {
                var form = $("form", table.$commonsearch);
                $("input[name='invite']", form).addClass("selectpage").data("source", "general/staff/index").data("primaryKey", "invite").data("field", "invite").data("orderBy", "id desc");
                Form.events.cxselect(form);
                Form.events.selectpage(form);
            });
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns:true,
                fixedRightNumber:1,
                fixedNumberWidth:200,
                search: false,
                columns: [
                    [
                        {field: 'order_user', title: __('商城类型'),searchList: {"1":"VIP商城","2":"收货商城"}, formatter: Table.api.formatter.flag},
                        {field: 'account', title: __('买家账号'), operate: 'LIKE'},
                        {field: 'order_sn', title: __('发货订单编号'), operate: 'LIKE'},
                        {field: 'title', title: __('标题'), operate: 'LIKE'},
                        {field: 'game', title: __('游戏'), operate: 'LIKE'},
                        {field: 'area', title: __('游戏区'), operate: 'LIKE'},
                        {field: 'server', title: __('游戏服'), operate: 'LIKE'},
                        {field: 'cross', title: __('跨区'), operate: 'LIKE'},
                        {field: 'invite', title: __('推广码'), operate: 'LIKE'},
                        {field: 'num', title: __('出货数量')},
                        {field: 'price', title: __('出货金额'), operate:'BETWEEN'},
                        {field: 'status', title: __('状态'),searchList: {"30":"异常订单","31":"扣押订单"}, formatter: Table.api.formatter.label},
                        {field: 'ontime', title: __('创建时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'personal.account', title: __('账号'), operate: 'LIKE'},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'manage',
                                    text: __(''),
                                    title: __('管控订单'),
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    icon: 'fa fa-retweet',
                                    url: 'risk/reorder/manage',

                                },
                                {
                                    name: 'chat',
                                    text: __(''),
                                    title: __('查看卖家聊天记录'),
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    icon: 'fa fa-bell-o',
                                    url: 'order/reorder/chat',

                                },
                                {
                                    name: 'online',
                                    text: __(''),
                                    title: __('联系买/卖家'),
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    icon: 'fa fa-handshake-o',
                                    url: 'order/reorder/online',

                                },

                                {
                                    name: 'kf_im',
                                    text: __(''),
                                    title: __('客服上传截图'),
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    icon: 'fa fa-folder-o',
                                    url: 'order/reorder/edit',

                                },

                                {
                                    name: 'info',
                                    text: __(''),
                                    title: __('详情'),
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    icon: 'fa fa-eye',
                                    url: 'order/reorder/info',

                                },
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ],
                onLoadSuccess: function (data) {
                    // 在表格第次加载成功后,刷新左侧菜单栏彩色小角标,支持一次渲染多个
                    // 如果需要在进入后台即显示左侧的彩色小角标,请使用服务端渲染方式,详情修改application/admin/controller/Index.php
                    Backend.api.sidebar({
                        'risk/reorder': data.extend.stat6
                    });
                    // Toastr.info("左侧角标已经刷新成功");
                }
            });

            //当表格数据加载完成时
            table.on('load-success.bs.table', function (e, data) {
                //这里可以获取从服务端获取的JSON数据
                //这里我们手动设置底部的值
                $("#stat6").text(data.extend.stat6);
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});